package com.lkk.cg;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import javax.annotation.Resource;

/**
 * Created by lkk on 2014/11/25.
 */

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:applicationContext.xml"})
public abstract class BaseTestCase extends AbstractTransactionalJUnit4SpringContextTests {

    protected Log log = LogFactory.getLog(getClass());

    @Resource
    protected SessionFactory sessionFactory;

    protected void flush() {
        sessionFactory.getCurrentSession().flush();
    }

    protected void clearDB(String entityName) {
        Session session = sessionFactory.getCurrentSession();
        log.debug("clear " + entityName + "s...");
        session.createQuery("delete from " + entityName).executeUpdate();
    }
}
